package hyrpt

class OutsourcedProcessingController {
    def dynamicQueryService
    def outsourcedProcessing(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def tableHeadList=[]
        def outsourcedProcessing=[]
        def pageSizeList = [10,20,50,100]
        def totalCount =0
        def outsourcedProcessingSumQty=[];
        if(params.EXPORT_CONTENT_NAME=='Excel'){
            params.SYS_QUERY_NAME = 'outsourcedProcessing'
            outsourcedProcessing = dynamicQueryService.queryForList(params)
            if (outsourcedProcessing.size() > 0) {
                tableHeadList = outsourcedProcessing[0].keySet()
            }
            params.SYS_QUERY_NAME = 'outsourcedProcessingCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT

            params.SYS_QUERY_NAME = 'outsourcedProcessingSumQty'
            outsourcedProcessingSumQty = dynamicQueryService.queryForList(params)
        }
        print(tableHeadList)
        [startno:params.startno?:'',
         endno:params.endno?:'',
         pageSize:pageSize,
         totalCount: totalCount,
         pageSizeList: pageSizeList,
         tableHeadList:tableHeadList,
         outsourcedProcessing:outsourcedProcessing,
         outsourcedProcessingSumQty:outsourcedProcessingSumQty,
         startTime:params.startTime?:'',
         endTime:params.endTime?:'',
         docId:params.docId?:'',
         partId:params.partId?:'',
         ZT:params.ZT?:'',
         yuanyin:params.yuanyin?:''
        ]
    }
    def outsourcedProcessingTwo(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def tableHeadList=[]
        def outsourcedProcessingTwo=[]
        def pageSizeList = [10,20,50,100]
        def totalCount =0


        params.SYS_QUERY_NAME = 'outsourcedProcessingTwo'
        outsourcedProcessingTwo = dynamicQueryService.queryForList(params)
        if (outsourcedProcessingTwo.size() > 0) {
            tableHeadList = outsourcedProcessingTwo[0].keySet()
        }
        params.SYS_QUERY_NAME = 'outsourcedProcessingTwoCount'
        totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT

        println(outsourcedProcessingTwo)
        [startno:params.startno?:'',
         endno:params.endno?:'',
         pageSize:pageSize,
         totalCount: totalCount,
         pageSizeList: pageSizeList,
         tableHeadList:tableHeadList,
         outsourcedProcessingTwo:outsourcedProcessingTwo,
         docId:params.docId?:'',
         partName:params.partName?:'',
         ZT:params.ZT?:''
        ]
    }



    def exportExcel() {
        def sysQueryName


        sysQueryName = params.SYS_QUERY_NAME

        params.startno = 1
        params.endno = 99999999999999999
        params.SYS_QUERY_NAME = sysQueryName

        def dataList = dynamicQueryService.queryForList(params)
        def tableHeadList =  []
        if(sysQueryName=='partFinList'){
            dataList=TranposUtils.colToRow('STEP_DESC','STEP_QTY',dataList)
            println(dataList)
        }
        if(dataList.size()>0){
            tableHeadList =  dataList[0].keySet()
        }
        String fileName = new String("${sysQueryName}.xls".getBytes("UTF-8"), "UTF-8");
        response.setContentType('application/vnd.ms-excel;charset=UTF-8')
        response.setHeader('Content-disposition', "attachment;filename=${fileName};charset=UTF-8")
        response.setCharacterEncoding("UTF-8");
        render(template: "export${params.EXPORT_CONTENT_NAME}", model: [dataList: dataList,tableHeadList:tableHeadList,startno:params.startno?:'',endno:params.endno?:''])
    }
}
